﻿#include "capture.h"

#include <QQmlApplicationEngine>
#include <QDebug>
#include <QApplication>
#include <QQuickWindow>
#include <QLabel>
#include <QScreen>
#include <QDesktopWidget>

Capture::Capture(QObject *parent) : QObject(parent)
{

}

void Capture::capturePic()
{
    qDebug() << "good";
//    QQmlApplicationEngine *engine = reinterpret_cast<QQmlApplicationEngine*>(qApp->property("engine").toInt());
//    //    qDebug() << engine->rootObjects();

//    foreach(QObject* obj, engine->rootObjects()) {
//        QQuickWindow* window = qobject_cast<QQuickWindow*>(obj);
//        if (window) {
//            QImage image = window->grabWindow();
//            qDebug() << image;


//        }
//    }
//    label->setPixmap(QPixmap::grabWindow(QApplication::desktop()->winId()));

    QApplication::screens();
    qDebug() << QApplication::desktop()->winId();

    for (QScreen * screen : QApplication::screens()) {
        QLabel *label = new QLabel(0);
        label->setPixmap(screen->grabWindow(0));
        label->show();
    }
}
